/*
* author: ADMathNoob
* created: 11/25/23 09:50:16
* problem: https://codeforces.com/contest/1896/problem/G
*/
/*
Comments about problem:
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
auto SolveTestCase = [&]() -> void {
int n;
cin >> n;
auto Ask = [&](auto x) -> int {
cout << '?';
for (int i = 0; i < n; i++) {
cout << ' ' << x[i] + 1;
}
cout << endl;
int r;
cin >> r;
--r;
auto it = find(x.begin(), x.end(), r);
assert(it != x.end());
return it - x.begin();
};
vector<deque<int>> groups(n);
for (int g = 0; g < n; g++) {
groups[g].resize(n);
iota(groups[g].begin(), groups[g].end(), g * n);
}
auto SetHead = [&](auto& group) {
int pos = Ask(group);
swap(group[0], group[pos]);
};
for (int g = 0; g < n; g++) {
SetHead(groups[g]);
}
vector<int> ret;
// all heads became heads by winning a race, and are thus not slow
for (int it = 0; it < n * n - (2 * n - 1); it++) {
vector<int> heads(n);
for (int g = 0; g < n; g++) {
heads[g] = groups[g][0];
}
int h = Ask(heads);
ret.push_back(heads[h]);
groups[h].pop_front();
for (int g = 0; g < n; g++) {
if (g == h) {
continue;
}
while (groups[h].size() < n && groups[g].size() >= 2) {
groups[h].push_back(groups[g].back());
groups[g].pop_back();
}
}
if (groups[h].size() < n) {
break;
}
SetHead(groups[h]);
}
vector<int> heads(n);
vector<int> slow;
for (int g = 0; g < n; g++) {
heads[g] = groups[g][0];
slow.insert(slow.end(), groups[g].begin() + 1, groups[g].end());
}
assert(slow.size() == n - 1);
for (int it = 0; it < n - 1; it++) {
SetHead(heads);
ret.push_back(heads[0]);
heads.erase(heads.begin());
heads.push_back(slow.back());
slow.pop_back();
}
ret.push_back(heads[0]);
assert(ret.size() == n * n - n + 1);
cout << '!';
for (int r : ret) {
cout << ' ' << r + 1;
}
cout << endl;
// n to set up the groups
// 2(n^2-n) to get the first n^2-n
// 1 for the last one
//
};
{
int tt;
cin >> tt;
for (int qq = 1; qq <= tt; qq++) {
SolveTestCase();
}
}
return 0;
}
1351. Count Negative Numbers in a Sorted Matrix | 617. Merge Two Binary Trees |
1450. Number of Students Doing Homework at a Given Time | 700. Search in a Binary Search Tree |
590. N-ary Tree Postorder Traversal | 589. N-ary Tree Preorder Traversal |
1299. Replace Elements with Greatest Element on Right Side | 1768. Merge Strings Alternately |
561. Array Partition I | 1374. Generate a String With Characters That Have Odd Counts |
1822. Sign of the Product of an Array | 1464. Maximum Product of Two Elements in an Array |
1323. Maximum 69 Number | 832. Flipping an Image |
1295. Find Numbers with Even Number of Digits | 1704. Determine if String Halves Are Alike |
1732. Find the Highest Altitude | 709. To Lower Case |
1688. Count of Matches in Tournament | 1684. Count the Number of Consistent Strings |
1588. Sum of All Odd Length Subarrays | 1662. Check If Two String Arrays are Equivalent |
1832. Check if the Sentence Is Pangram | 1678. Goal Parser Interpretation |
1389. Create Target Array in the Given Order | 1313. Decompress Run-Length Encoded List |
1281. Subtract the Product and Sum of Digits of an Integer | 1342. Number of Steps to Reduce a Number to Zero |
1528. Shuffle String | 1365. How Many Numbers Are Smaller Than the Current Number |